<?php

namespace App\Http\Requests\Role;

use App\Http\Requests\ApiRequest;

class StoreRequest extends ApiRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * 'permission/role_manage/RoleDataAdd'：前端路由
     *
     * @return bool
     */
    public function authorize()
    {
        if(is_bool(self::checkPermission('permission/role_manage/RoleDataAdd'))){
            return self::checkPermission('permission/role_manage/RoleDataAdd');
        }else{
            return false;
        }
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'name' => 'required|string|unique:roles,name',
        ];
    }

    /**
     * 获取已定义验证规则的错误消息。
     *
     * @return array
     */
    public function messages()
    {
        return [
            'name.required'=>'请输入角色名称',
            'name.string'=>'角色名称必须为字符类型',
            'name.unique'=>'该权角色已存在',
        ];
    }
}
